file_name = 'love_reasons.txt'
with open(file_name, 'a') as file_object:
    flag = 1
    while flag:
        print('You can enter "b" to end.')
        love_reasons = input('Why do you love programming?\n')
        if love_reasons == 'b':
            flag = 0
        else:
            file_object.write(love_reasons + '\n')
